package itsm.isperp.module.controller.kpi;

import itsm.isperp.framework.core.context.ContextHolder;
import itsm.isperp.module.entity.app.AppDict;
import itsm.isperp.module.entity.kpi.KpiSetting;
import itsm.isperp.module.service.app.AppDictService;
import itsm.isperp.module.service.kpi.KpiSettingService;
import itsm.isperp.module.service.project.ProjProjectService;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * 
 * 
 * 
 * @author lizx
 * @date 2015-8-24
 * @since 1.0
 * 
 */
@Controller
@RequestMapping("kpi/main")
public class KpiMainController {

	@Autowired
	protected KpiSettingService kpiSettingService;

	@RequestMapping(value = { "view" })
	public ModelAndView view(String moduleName, HttpServletRequest req) {
		ModelAndView mv = new ModelAndView("kpi/main/view");
		
		List<KpiSetting> list = kpiSettingService.findByModelName(moduleName);
		AppDictService appDictService = ContextHolder
				.getSpringBean("appDictService");
		ProjProjectService projProjectService = ContextHolder
				.getSpringBean("projProjectService");
		List<AppDict> kpiTypes = appDictService.findByType("KPI_TYPE"); 
		mv.addObject("kpiTypes", kpiTypes);
		mv.addObject("kpis", list);
		mv.addObject("moduleName", moduleName);
		mv.addObject("projects",
				projProjectService.findAllPublished("id", "name"));
		return mv;
	}

}
